﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArticleManager.DataClasses
{
    public class ColumnData
    {
        bool Exists;
        string createQuery;
        string strName;
        string strType;
        string strTableName;

        public ColumnData()
        {
            Exists = false;
            createQuery = string.Empty;
            strName = string.Empty;
            strType = string.Empty;
        }

        public ColumnData(string sName,string sType)
        {
            Exists = false;
            createQuery = string.Empty;
            strName = string.Empty;
            strType = string.Empty;
        }

        public override string ToString()
        {
            return strName;
        }

        public string Name
        {
            get { return this.strName; }
            set { this.strName = value; }
        }

        public string Table
        {
            get { return this.strTableName; }
            set { this.strTableName = value; }
        }

        public string Type
        {
            get { return this.strType; }
            set { this.strType = value; }
        }

        public string Query
        {
            get 
            { 
                createQuery = "ALTER TABLE "+strTableName+" ADD COLUMN "+strName+" "+strType;
                return this.createQuery; 
            }
            set { this.createQuery = value; }
        }
        public bool Exist
        {
            get { return this.Exists; }
            set { this.Exists = value; }
        }

    }
    
    public class ColumnDataCollection : System.Collections.CollectionBase
    {
        public int Add(ColumnData value)
        {
            return base.List.Add(value as object);
        }

        public void Remove(ColumnData value)
        {
            base.List.Remove(value as object);
        }

        public void Insert(int index, ColumnData value)
        {
            base.List.Insert(index, value as object);
        }

        public bool Contains(ColumnData value)
        {
            return base.List.Contains(value as object);
        }

        public ColumnData this[int index]
        {
            get { return base.List[index] as ColumnData; }
        }

        public int this[string name]
        {
            get
            {
                for (int i = 0; i < base.List.Count; i++)
                {
                    if (base.List[i].ToString().CompareTo(name) == 0)
                        return i;
                }
                return -1;
            }
        }
    }
}
